//子弹基础类
//1.生成子弹图片
//2.更换子弹的刚体
//3.负责子弹的移动，或者给力
//4.负责子弹的停止

module py2Obj {


	export class basicObj {
		//保存外部的物理世界
		public m_world: P2World;
		public m_gamePanle: any;
		public m_skin: MImage;
		public m_body: p2.Body;
		public m_removeSkins: any[] = [];//需要删除刚体的皮肤
		public objkind: number;
		public m_num:number=5;
		public constructor(world: any, gamePanle: any, romveSkins: any) {

			this.m_world = world;
			this.m_gamePanle = gamePanle;


		
			this.m_removeSkins = romveSkins;
		}

		public getBody() {
			return this.m_body;

		}
		/**设置初始化 */
		public init() {
			this.m_body = this.createMyRigidbody();


		}
		/**设置材质 */
		public setMaterial(material: p2.Material): void {

			this.m_body.shapes[0].material = material;

			var roleAndStoneMaterial = new p2.ContactMaterial(material, material, { restitution: 0.7, friction: 0 });//弹性，摩擦力
			this.m_world.p2World.addContactMaterial(roleAndStoneMaterial);
		}
		/**设置位置 */
		public setPostion(x, y) {
			this.m_body.position = [x, y];

		}
		/**设置冲量 */
		public setBallImpulse(): void {
			var x = Math.random() > 0.5 ? -5000 : 5000;
			var y = -5000 - (Math.random() * 2000);
			this.setForce(x, y);
		}
		/**设置力 */
		public setForce(x, y): void {
			this.m_body.fixedX = false;
			this.m_body.fixedY = false;
			this.m_body.applyImpulse([x, y], [0, 0]);
		}

		/** 创建皮肤*/
		public createSkin(name: string): MImage {
			var skin: NumImage = new NumImage(name);
			
			skin.x = -500;//避免在一出现的时候会在左上角闪现
			skin.setAnchorCenter();
			this.m_gamePanle.addChild(skin);
			return skin;

		}
		/**固定我们的球 */
		public fixObj() {

			this.m_body.fixedX = true;
			this.m_body.fixedY = true;
		}
		public remove() {
			//this.m_removeSkins.push(this.m_body.userData.skin);
			this.m_world.removeBodys.push(this.m_body);
		}
	
		/** 创建球刚体*/
		public createMyRigidbody(): p2.Body {
			var world: P2World = this.m_world;
			var skin: MImage = this.createSkin("ball_png");
			var body: p2.Body = world.createCircleBodyShape(skin.width >> 1);
			body.userData.skin = skin;
			body.userData.data = this;
			body.mass = 0;//质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
			//body.gravityScale=0;
			var shape = body.shapes[0];
			shape.collisionGroup = 2;//010与001为0，010与110为1
			return body;
		}
		public removebullet(ba:clrcle) {
			this.m_world.removeBodys.push(ba.getBody());
			//this.m_removeSkins.push(ba.getBody().userData.skin);
		}

		public getCollision(otherBody:basicObj)
		{

		}


	}
}